#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QShortcut* shortcut_add = new QShortcut(this);
    shortcut_add->setKey(QKeySequence("+"));

    QShortcut* shortcut_sub = new QShortcut(this);
    shortcut_sub->setKey(QKeySequence("="));
    connect(shortcut_add,&QShortcut::activated,this,&Widget::handle_add);
    connect(shortcut_sub,&QShortcut::activated,this,&Widget::handle_sub);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::handle_add()
{
    int val = ui->horizontalSlider->value();
    if(val>=ui->horizontalSlider->maximum())
        return;
    val+=5;
    QRect rect  = this->geometry();
    this->setGeometry(rect.x(),rect.y(),val,rect.height());
    ui->horizontalSlider->setValue(val);
    ui->label->setText(QString::number(val));
}
void Widget::handle_sub()
{
    int val = ui->horizontalSlider->value();
    if(val<=ui->horizontalSlider->minimum())
       return;
    val-=5;
    QRect rect  = this->geometry();
    this->setGeometry(rect.x(),rect.y(),val,rect.height());
    ui->horizontalSlider->setValue(val);
    ui->label->setText(QString::number(val));
}
